#pragma once

#include <QWidget>
namespace Ui { class FramelessWidget; };
enum Edge {
    Edge_No,
    Edge_Left,
    Edge_BottomLeft,
    Edge_Bottom,
    Edge_BottomRight,
    Edge_Right,
    Edge_TopRight,
    Edge_Top,
    Edge_TopLeft,
};
class FramelessWidget : public QWidget
{
    Q_OBJECT

public:
    FramelessWidget(QWidget *parent = Q_NULLPTR);
    ~FramelessWidget();
public:
    void setIcon(const QPixmap &icon);
    void setTitle(const QString &title);
    void setContent(QWidget *content);
protected:
    virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
    virtual void mouseMoveEvent(QMouseEvent *event) override;
    virtual void mousePressEvent(QMouseEvent *event) override;
    virtual void mouseReleaseEvent(QMouseEvent *event) override;
    virtual void leaveEvent(QEvent *event) override;
private:
    Edge edge(const QPointF &pos);
    void setMouseTracking(QWidget *widget);
private slots:
    void on_btnClose_clicked();
    void on_btnMax_clicked();
    void on_btnMin_clicked();
private:
    Ui::FramelessWidget *ui;
    QWidget *m_contentWidget = nullptr;
    QPointF m_pressedPoint;
    bool m_titlePressed = false;
    bool m_edgePressed = false;
    Edge m_edge = Edge_No;
};
